package com.sc.nft.dto;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.EcologyCollectionNodeConf;
import com.sc.nft.mapper.EcologyCollectionNodeConfMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.List;

/**
 * 生态-节点藏品-配置(sc_ecology_collection_node_conf)数据DAO
 *
 * @author Sun
 * @since 2023-10-13 17:22:11
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class EcologyCollectionNodeConfDao extends ServiceImpl<EcologyCollectionNodeConfMapper, EcologyCollectionNodeConf> {

    public List<Long> getCollectionList() {
        QueryWrapper<EcologyCollectionNodeConf> wrapper = new QueryWrapper<>();
        wrapper.select("collection_id"); // 指定要查询的字段
        return listObjs(wrapper, obj -> Long.parseLong(obj.toString()));
    }

    public Integer getCountByCollectionId(Long collectionId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCollectionNodeConf::getCollectionId, collectionId);
        return count(wrapper);
    }


    public Integer getCountByCollectionIdAndRelevanceId(Long collectionId,Long relevanceId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCollectionNodeConf::getCollectionId, collectionId);
        wrapper.eq(EcologyCollectionNodeConf::getConfRelevanceId, relevanceId);
        return count(wrapper);
    }

    public EcologyCollectionNodeConf getOneByCollectionId(Long collectionId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCollectionNodeConf::getCollectionId, collectionId);
        return getOne(wrapper);
    }

    public EcologyCollectionNodeConf getOneByCollectionIdAndRelevanceId(Long collectionId,Long relevanceId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(EcologyCollectionNodeConf::getCollectionId, collectionId);
        wrapper.eq(EcologyCollectionNodeConf::getConfRelevanceId, relevanceId);
        return getOne(wrapper);
    }

    public List<EcologyCollectionNodeConf> listByRelevanceId(Long relevanceId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyCollectionNodeConf::getConfRelevanceId,relevanceId);
        return list(lambdaQueryWrapper);
    }

    public Boolean removeByRelevanceId(Long relevanceId) {
        LambdaQueryWrapper<EcologyCollectionNodeConf> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EcologyCollectionNodeConf::getConfRelevanceId,relevanceId);
        return remove(lambdaQueryWrapper);
    }
}